<template>
  <div class="box">
    <h2>Son2 子组件</h2>
    从vuex中获取的值:<label>{{ count }}</label>
    <br />
    <button @click="subCount(1)">值 - 1</button>
    <button @click="subCount(5)">值 - 5</button>
    <button @click="subCount(10)">值 - 10</button>
    <button @click="setAsyncCount(888)">1s后改成888</button>
    <p>----------------getters使用-开始-----------------</p>
    <div>state中数组: {{ list }}</div>
    <div>getters中数组: {{ filterList }}</div>
    <p>----------------getters使用-结束-----------------</p>
    <p>----------------modules数据操作-开始-----------------</p>
    <h4>state:</h4>
    <div>user模块: {{ userInfo }}</div>
    <div>setting模块: {{ theme }} - {{ desc }}</div>
    <h4>getters:</h4>
    <div>大写的名字: {{ uppcaseName }}</div>
    <button @click="changeUserInfo({name: 'nonono', age: 999})">修改用户信息</button>
    <p>----------------modules使用-结束-----------------</p>
  </div>
</template>

<script>
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex'
export default {
  name: 'Son2Com',
  computed: {
    // 根级别映射
    ...mapState(['count', 'list']),
    ...mapGetters(['filterList']),

    // 模块级别映射
    ...mapState('user', ['userInfo']),
    ...mapState('setting', ['theme', 'desc']),
    ...mapGetters('user', ['uppcaseName'])
  },
  methods: {
    // 根级别映射
    ...mapMutations(['subCount']),
    ...mapActions(['setAsyncCount']),

    // 模块级别映射
    ...mapMutations('user', ['changeUserInfo'])
  }
}
</script>

<style lang="css" scoped>
.box {
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>
